import React, { useState, useEffect } from 'react';
import { EchartsComp } from './echarts';
import { DeviationTariff, DeductionIncome } from './helper';
import { useThemeChange } from '@/hooks';

export function ChartDealTariff({ data = {}, scale = 1, getRef = () => {} }) {
  const [config, setConfig] = useState();
  const { theme } = useThemeChange();
  useEffect(() => {
    setConfig({ ...DeviationTariff(data, scale) });
  }, [data]);
  useEffect(() => {
    setTimeout(() => {
      setConfig({ ...DeviationTariff(data, scale) });
    }, 1);
  }, [theme]);
  return <EchartsComp config={config} getRef={getRef} />;
}
export function ChartDealIncome({ data = {}, scale = 1, getRef = () => {} }) {
  const [config, setConfig] = useState();
  const { theme } = useThemeChange();
  useEffect(() => {
    setConfig({ ...DeductionIncome(data, scale) });
  }, [data]);
  useEffect(() => {
    setTimeout(() => {
      setConfig({ ...DeductionIncome(data, scale) });
    }, 1);
  }, [theme]);
  return <EchartsComp config={config} getRef={getRef} />;
}
